/* *****************************************************************************
 * JFab (http://code.google.com/p/jfab)
 * Copyright (c) 2011 JFab.org
 * Admin jfab@jeffreythompson.net
 *
 * See the file "LICENSE.txt" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * *****************************************************************************/

package org.jfab.core.collection;

import java.util.ArrayList;
import java.util.Collection;

import org.apache.commons.lang3.Validate;
import org.jfab.core.model.Modifier;

/**
 * Provides a modifier list.
 */
public class ModifierList extends CGList<String>
{
    /**
     * Construct this object.
     */
    public ModifierList()
    {
        super(new ArrayList<String>());
    }

    /**
     * Construct this object with the given parameter.
     * 
     * @param modifiers Modifiers.
     */
    public ModifierList(final Collection<String> modifiers)
    {
        this();

        getList().addAll(modifiers);
    }

    /**
     * Construct this object with the given parameter.
     * 
     * @param modifiers java.lang.reflect.Modifier.
     */
    public ModifierList(final int modifiers)
    {
        this();

        if (java.lang.reflect.Modifier.isPublic(modifiers))
        {
            add(Modifier.PUBLIC.getName());
        }

        if (java.lang.reflect.Modifier.isProtected(modifiers))
        {
            add(Modifier.PROTECTED.getName());
        }

        if (java.lang.reflect.Modifier.isPrivate(modifiers))
        {
            add(Modifier.PRIVATE.getName());
        }

        if (java.lang.reflect.Modifier.isAbstract(modifiers))
        {
            add(Modifier.ABSTRACT.getName());
        }

        if (java.lang.reflect.Modifier.isFinal(modifiers))
        {
            add(Modifier.FINAL.getName());
        }

        if (java.lang.reflect.Modifier.isInterface(modifiers))
        {
            add(Modifier.INTERFACE.getName());
        }

        if (java.lang.reflect.Modifier.isNative(modifiers))
        {
            add(Modifier.NATIVE.getName());
        }

        if (java.lang.reflect.Modifier.isStatic(modifiers))
        {
            add(Modifier.STATIC.getName());
        }

        if (java.lang.reflect.Modifier.isStrict(modifiers))
        {
            add(Modifier.STRICT.getName());
        }

        if (java.lang.reflect.Modifier.isSynchronized(modifiers))
        {
            add(Modifier.SYNCHRONIZED.getName());
        }

        if (java.lang.reflect.Modifier.isTransient(modifiers))
        {
            add(Modifier.TRANSIENT.getName());
        }

        if (java.lang.reflect.Modifier.isVolatile(modifiers))
        {
            add(Modifier.VOLATILE.getName());
        }

        if (((modifiers & Modifier.ANNOTATION.getValue().intValue()) != 0))
        {
            add(Modifier.ANNOTATION.getName());
        }

        if (((modifiers & Modifier.ENUM.getValue().intValue()) != 0))
        {
            add(Modifier.ENUM.getName());
        }

        if (((modifiers & Modifier.SYNTHETIC.getValue().intValue()) != 0))
        {
            add(Modifier.SYNTHETIC.getName());
        }
    }

    /**
     * Construct this object with the given parameter.
     * 
     * @param modifier Modifier. (required)
     */
    public ModifierList(final Modifier modifier)
    {
        this();

        Validate.notNull(modifier, "modifier is null");

        getList().add(modifier.getName());
    }

    /**
     * @return true if this contains abstract.
     */
    public boolean isAbstract()
    {
        return contains(Modifier.ABSTRACT.getName());
    }

    /**
     * @return true if this contains annotation.
     */
    public boolean isAnnotation()
    {
        return contains(Modifier.ANNOTATION.getName());
    }

    /**
     * @return true if this contains enum.
     */
    public boolean isEnum()
    {
        return contains(Modifier.ENUM.getName());
    }

    /**
     * @return true if this contains final.
     */
    public boolean isFinal()
    {
        return contains(Modifier.FINAL.getName());
    }

    /**
     * @return true if this contains interface.
     */
    public boolean isInterface()
    {
        return contains(Modifier.INTERFACE.getName());
    }

    /**
     * @return true if this contains native.
     */
    public boolean isNative()
    {
        return contains(Modifier.NATIVE.getName());
    }

    /**
     * @return true if this contains private.
     */
    public boolean isPrivate()
    {
        return contains(Modifier.PRIVATE.getName());
    }

    /**
     * @return true if this contains protected.
     */
    public boolean isProtected()
    {
        return contains(Modifier.PROTECTED.getName());
    }

    /**
     * @return true if this contains public.
     */
    public boolean isPublic()
    {
        return contains(Modifier.PUBLIC.getName());
    }

    /**
     * @return true if this contains static.
     */
    public boolean isStatic()
    {
        return contains(Modifier.STATIC.getName());
    }

    /**
     * @return true if this contains strict.
     */
    public boolean isStrict()
    {
        return contains(Modifier.STRICT.getName());
    }

    /**
     * @return true if this contains synchronized.
     */
    public boolean isSynchronized()
    {
        return contains(Modifier.SYNCHRONIZED.getName());
    }

    /**
     * @return true if this contains synthetic.
     */
    public boolean isSynthetic()
    {
        return contains(Modifier.SYNTHETIC.getName());
    }

    /**
     * @return true if this contains transient.
     */
    public boolean isTransient()
    {
        return contains(Modifier.TRANSIENT.getName());
    }

    /**
     * @return true if this contains volatile.
     */
    public boolean isVolatile()
    {
        return contains(Modifier.VOLATILE.getName());
    }
}
